package self;

import java.util.Arrays;

public class PaiXu {
    public static void main(String[] args) {
        PaiXu paixu = new PaiXu();
        paixu.maoPao();
        paixu.chaRu();
        paixu.xuanZe();
    }

    private void xuanZe() {
        int[] nums = {1,5,9,2,8,3,7,4,6};
        for (int i = 0; i < nums.length; i++) {
            int index = i;
            int temp = nums[index];
            for (int j = i; j < nums.length; j++) {
                if (temp>nums[j]){
                    temp = nums[j];
                    index = j;
                }
            }
            nums[index] = nums[i];
            nums[i] = temp;
        }
        nums = new int[]{1, 5, 9, 2, 8, 3, 7, 4, 6};
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i+1; j < nums.length; j++) {
                if (nums[i]>nums[j]){
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(nums));
    }

    private void chaRu() {
        int[] nums = {1,5,9,2,8,3,7,4,6};
        for (int i = 1; i < nums.length; i++) {
            for (int j = i; j > 0; j--) {
                if (nums[j]<nums[j-1]){
                    int temp = nums[j];
                    nums[j] = nums[j-1];
                    nums[j-1] = temp;
                }
            }
        }
        nums = new int[]{1, 5, 9, 2, 8, 3, 7, 4, 6};
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = i+1; j > 0; j--) {
                if (nums[j] < nums[j-1]){
                    int temp = nums[j];
                    nums[j] = nums[j-1];
                    nums[j-1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(nums));
    }

    private void maoPao() {
        int[] nums = {1,5,9,2,8,3,7,4,6};
        for (int i = 0; i < nums.length-1; i++) {
            for (int j = 0; j < nums.length-1-i; j++) {
                if (nums[j]>nums[j+1]){
                    int temp = nums[j];
                    nums[j] = nums[j+1];
                    nums[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(nums));
    }

}

